package com.freesun.autoui.share;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by yangfei on 13-12-31.
 */
public class SetupBrowser {
    private static Logger log = LoggerFactory.getLogger(SetupBrowser.class.getClass());

    private static WebDriver driver;

    /**
     * @desc  启动不同浏览器
     * @param remoteIp
     * @param browser
     * @throws java.net.MalformedURLException
     */
   public static WebDriver initBrower(String remoteIp,String browser) {
       if (browser.equals("firefox")){
           try {
               driver = new RemoteWebDriver(new URL(remoteIp), DesiredCapabilities.firefox());
           } catch (MalformedURLException e) {
               e.printStackTrace();
               log.error(e.getLocalizedMessage());
           }
           log.info("启动 firefox");
       } else if (browser.equals("ChromeDriver")){
           try {
               driver = new RemoteWebDriver(new URL(remoteIp), DesiredCapabilities.chrome());
           } catch (MalformedURLException e) {
               e.printStackTrace();
               log.error(e.getLocalizedMessage());
           }
           log.info("启动chrome");
       }else if (browser.equals("InternetExplorerDriver")){
           try {
               driver = new RemoteWebDriver(new URL(remoteIp), DesiredCapabilities.chrome());
           } catch (MalformedURLException e) {
               e.printStackTrace();
               log.error(e.getLocalizedMessage());
           }
           log.info("启动ie");
       }else{
           log.info("no");
       }
       return driver;
   }

}
